Skip to content

Add image/apng media type - #1559

Merged
olivervogel merged 1 commit into
Intervention:developfrom
nlemoine:bugfix/apng-media-type
Nov 23, 2026
Merged

olivervogel merged 1 commit into
Intervention:developfrom
nlemoine:bugfix/apng-media-type

Conversation

@nlemoine

Copy link
Copy Markdown
Contributor

On PHP 8.6 the GD driver fails to decode an animated PNG:

$manager = ImageManager::usingDriver(GdDriver::class);

$manager->decodeBinary(file_get_contents('animation.png'));
// Unsupported image source type "string"

$manager->decodePath('animation.png');
// File contains unsupported image format

PHP 8.6 bundles libmagic 5.48, and finfo now reports image/apng for a PNG with an acTL chunk, where PHP 8.5 said image/png. The GD decoders get the media type from finfo, image/apng is not a case of MediaType, so they throw Unsupported media type (MIME) image/apng. The caller does not see that message, only the generic one above.

image/apng is now an alias media type of the PNG format, like image/x-png or image/x-bmp3 (#1427). It comes after IMAGE_PNG, so Format::PNG->mediaType() and the encoders still give image/png. GD keeps reading only the first frame, same as before.

The decoder tests use a new 229 bytes APNG fixture. They only fail without the change on PHP 8.6, on older versions finfo still says image/png.

Imagick is not affected, it does not use finfo.

@olivervogel

Copy link
Copy Markdown
Member

Thanks for finding that @nlemoine . That's an important fix that probably wouldn't have been noticed. Could you please remove the test image? You can leave the (failing) tests. I'll add my own.

PHP 8.6 bundles libmagic 5.48, which reports animated PNG files as
image/apng. The GD decoders read the media type through finfo, could
not map this value and threw, so every decoder in the chain failed and
the user got "Unsupported image source type".

Map image/apng to the PNG format, like the other alias media types.
@nlemoine
nlemoine force-pushed the bugfix/apng-media-type branch from a1544b4 to 8cf1218 Compare November 23, 2026 15:02
@nlemoine

nlemoine commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@olivervogel The image has been removed, you can add your own.

@olivervogel
olivervogel merged commit 8cf1218 into Intervention:develop Nov 23, 2026
0 of 8 checks passed
@olivervogel

Copy link
Copy Markdown
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants